local U = require "packages.utility.utility"

local skel = fk.CreateSkill {
  name = "rmt__pozhi",
  tags = {Skill.Hidden},
}

Fk:loadTranslationTable{
  ["rmt__pozhi"] = "破桎",
  [":rmt__pozhi"] = "隐匿技，你登场时，失去任意个隐匿技（若为首次发动此技能，则必须失去〖缚枝〗），然后对至多等量的角色各造成1点伤害。",

  ["#rmt__zhuozheng-choice"] = "琢政：你可以修改一个技能的时机为“与你体力值和手牌数均相等的角色出牌阶段结束时”",
  ["#rmt__pozhi-choice"] = "破桎：请选择失去任意个隐匿技，然后对等量名角色造成伤害",
  ["#rmt__pozhi1-choice"] = "破桎：请选择失去任意个隐匿技（本次必须失去“缚枝”），然后对等量名角色造成伤害",
  ["#rmt__pozhi-damage"] = "破桎：对至多%arg名角色各造成1点伤害",

  ["$rmt__pozhi1"] = "海压竹节低复举，风吹山棱晦转明！",
  ["$rmt__pozhi2"] = "富有四海而不恣睢，天下与桎梏何异？",
}

skel:addEffect(U.GeneralAppeared, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasShownSkill(skel.name, true)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local choices = {}
    for _, skill in ipairs(player.player_skills) do
      if skill:hasTag(Skill.Hidden) then
        table.insert(choices, skill.name)
      end
    end
    if #choices == 0 then return end
    local prompt = "#rmt__pozhi-choice"
    if player:usedSkillTimes(skel.name, Player.HistoryGame) == 1 and table.contains(choices, "rmt__fuzhi") then
      prompt = "#rmt__pozhi1-choice"
    end
    local choice = room:askToChoices(player, {
      choices = choices, min_num = 1, max_num = #choices, skill_name = skel.name, prompt = prompt,
      cancelable = false, detailed = true,
    })
    if prompt == "#rmt__pozhi1-choice" then
      table.insertIfNeed(choice, "rmt__fuzhi")
    end
    room:handleAddLoseSkills(player, "-"..table.concat(choice, "|-"), nil, true, false)
    if player.dead then return end
    local total = #choice
    local tos = room:askToChoosePlayers(player, {
      targets = room.alive_players, min_num = 1, max_num = total, skill_name = skel.name,
      prompt = "#rmt__pozhi-damage:::"..total,
    })
    if #tos > 0 then
      room:sortByAction(tos)
      for _, p in ipairs(tos) do
        if not p.dead then
          room:damage{
            from = player,
            to = p,
            damage = 1,
            skillName = skel.name,
          }
        end
      end
    end
  end,
})

return skel
